package com.wdy.util;

import java.text.ParseException;

import org.apache.commons.lang.time.DateUtils;

public class TypeUtil {
	public static Object getType(Object value, int type){
		Object o = null;
		if(null != value && !"".equals(value)){
			switch(type){
			case 1: o = new Integer(value.toString());break;
			case 2: o = new Float(value.toString());break;
			case 10: 
				try {
					String tempStr = value.toString();
					o = DateUtils.parseDate(tempStr.substring(0, tempStr.indexOf("T")), new String[]{"yyyy-MM-dd"});
//					o = DateUtils.parseDate(tempStr.substring(0, tempStr.indexOf("+")), new String[]{"yyyy-MM-dd'T'HH:mm:ss"});
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			break;
			default: o = value;
			}
		}else{
			return "";
		}
		return o;
	}
	
	public static Object[] getType(Object[] values, int[] types){
		Object[] tempArray = new Object[values.length];
		Object o = null;
		for(int i = 0; i < values.length; i++){
			o = getType(values[i], types[i]);
			tempArray[i] = o;
		}
		return tempArray;
	}
}
